# 3.9 Axis-X&Y Joystick Module ## 3.9.1 Overview Axis-X&Y Joystick is a high-precision input device for bidirectional control. Its X and Y axes are separated to control horizontal and vertical movements respectively. This module contains 10K resistance so that it ensures the stability and accuracy of signals. ## 3.9.2 Schematic Diagram ![image-20240701134032989](./media/6-9-2.png) ESP32 Axis-X&Y Joystick works based on a two-axis potentiometer that detects movements on two axes. When the joystick moves on axis X or Y, the resistance of the potentiometer changes, outputting analog voltage signals. After being received by ESP32 analog input pin (ADC), these signals will be read by ESP32 board and converted to digital values. Therefore, the joystick coordinate can be easily revealed during controlling. ## 3.9.3 Code Blocks ![image-20240701141348645](./media/j33.png) This block reads the values of Axis-X&Y Joystick module. You can set pins and axis. ## 3.9.4 Test Code ## 3.9.4.1 Build Code There are two ways to upload the code: directly open the code file we provide; or manually build blocks. **Directly open the code file we provide:** 1. Click ![](./media/j68.png) and choose `Load from your computer` ![](./media/j67.png) 2. We have already downloaded the codes on computer desktop, so open the file and choose `3-9-joystick.sb3` **Manually build blocks:** 1. In ![events](./media/events.png), find ![j1](./media/j1.png) block. 2. In ![serial](./media/serial.png), find ![j12](./media/j12.png) block and set baud rate to 9600, and put it under ![j1](./media/j1.png). 3. In ![control](./media/control.png), drag ![j2](./media/j2.png).![6-4-4-1-1](./media/6-2-4-1-1.png) ![6-2](./media/6-2-4-1-2.png) 4. In ![serial](./media/serial.png), put ![j13](./media/j13.png) into ![j2](./media/j2.png), change printing content into “X:” and set to no-warp. 5. Add another ![image-20240701141959486](./media/6-9-4-1-1.png) and set to no-warp 6. In ![image-20240701141246757](./media/joy.png), find and drag block ![j14](./media/j33.png) into the printing content box of ![j13](./media/6-9-4-1-1.png) , set pin to IO35 and axis to X ![image-20241017090054348](./media/6-9-4-1-2.png) 7. Duplicate block ![image-20240701142500257](./media/6-9-4-1-3.png), and modify the printing content “X:” into “ Y:”(the two spaces separates the two values to be output). Change pin to IO39 and set axis to Y. 8. Add a delay of 0.3s for better observing results. **Complete Test Code** ![](./media/6-9-4-1-4.png) ## 3.9.4.2 Test Result After uploading code, the serial monitor prints the values on axis X and Y. Toggle the joystick, and these value changes. ![image-20240701143706206](./media/6-9-4-2.png)